//
//  TTBeiLvViewCell.m
//  TaoTuo
//
//  Created by admin on 2019/11/8.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTBeiLvViewCell.h"

@interface TTBeiLvViewCell ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UITextField *textField;

@end

@implementation TTBeiLvViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 30)];
    self.textField.leftView = leftView;
    self.textField.leftViewMode = UITextFieldViewModeAlways;
    
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor whiteColor];
    self.textField.layer.cornerRadius = 5;
    
    [self.textField.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
        self.model.content = x;
    }];
    
    
}

- (void)setModel:(TTBeiLvModel *)model
{
    _model = model;
    self.titleLabel.text = model.title;
    self.textField.text = model.content;
    
    self.textField.hidden = model.hiddenTF;
    
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *text = [textField.text stringByAppendingString:string];
    // 最多输入小数点后两位
    NSString *regex = @"[1-9]{1,6}\\.\\d{0,2}";
    NSString *regex1 = @"[1-9]{1,6}";

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex1];
    return  [predicate evaluateWithObject:text] || [predicate1 evaluateWithObject:text];
}


@end
